<%--
  Created by IntelliJ IDEA.
  User: 黄志鹏
  Date: 2019/5/26
  Time: 16:09
  员工及管理员修改信息的页面
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<c:set var="path" value="${pageContext.request.contextPath}"></c:set>
<head>
    <meta charset="utf-8">
    <title>设置我的资料</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${path}/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${path}/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">设置我的资料</div>
                <div class="layui-card-body" pad15>
                    <form id="updatefrom">
                        <div class="layui-form" lay-filter="">
                            <div class="layui-form-item">
                                <input type="hidden" value="${employee.empid}" id="empid">
                                <label class="layui-form-label">我的角色</label>
                                <div class="layui-input-inline">
                                    <select name="empstatus" lay-verify="">
                                        <c:if test="${employee.empstatus==2}">
                                            <option value="1" selected>管理员</option>
                                            <option value="2" disabled>普通员工</option>
                                        </c:if>
                                        <c:if test="${employee.empstatus==0}">
                                            <option value="1" disabled>普通员工</option>
                                            <option value="2" selected>管理员</option>
                                        </c:if>
                                    </select>
                                </div>
                                <div class="layui-form-mid layui-word-aux">当前角色不可更改为其它角色</div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">用户名</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="username" value="${employee.empname}" id="empname"
                                           class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">性别</label>
                                <div class="layui-input-block" id="sex">
                                    <c:if test="${employee.empsex=='男'}">
                                        <input type="radio" name="empsex" value="男" title="男" checked>
                                        <input type="radio" name="empsex" value="女" title="女">
                                    </c:if>
                                    <c:if test="${employee.empsex=='女'}">
                                        <input type="radio" name="empsex" value="男" title="男">
                                        <input type="radio" name="empsex" value="女" title="女" checked>
                                    </c:if>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">手机</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="empphone" value="${employee.empphone}" lay-verify="phone" id="empphone"
                                           autocomplete="off" readonly class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">手机号用于登录使用，不可更改如需更改请联系管理员</div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" name="emppassword" lay-verify="password" id="emppassword"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                 <%--  <button class="layui-btn" lay-submit lay-filter="setmyinfo" id="update">确认修改
                                    </button>--%>
                                    <input type="button" class="layui-btn" value="确认修改" id="update">
                                </div>
                            </div>
                        </div>
                    </form>
                </div>

            </div>
        </div>
    </div>
</div>

<script src="${path}/layuiadmin/layui/layui.js"></script>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
     layui.config({
         base: '${path}/layuiadmin/' //静态资源所在路径
     }).extend({
         index: 'lib/index' //主入口模块
     }).use(['index', 'set']);

    $("#update").click(function () {
        layui.use(['laypage', 'layer'], function () {
            var laypage = layui.laypage, layer = layui.layer;
            $.ajax({
                url: "${path}/admin.action/updateEmployeePersonalData",
                dataType: "json",
                type: "put",
                data: {
                    "empid":$("#empid").val(),
                    "empname": $("#empname").val(),
                    "emppassword":$("#emppassword").val(),
                    "empsex":$("#sex input[name='empsex']").val()
                },success:function (data) {
                    if(data.msg=="修改成功"){
                        layer.msg(data.msg,{icon : 1,time : 2000	},function () {
                            //修改成功
                            location.reload();
                        });
                    }else {
                        layer.msg(data.msg,{icon : 2,time : 2000	},function () {
                            //修改失败
                            location.reload();
                        });
                    }
                }
            });
        });
    });
</script>
</body>
</html>